package br.ufpe.cin.msc.jrsj2.recommender.message;

import java.io.IOException;
import java.io.StringReader;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public abstract class ProgramInfo {

	private static class MessageHandler extends DefaultHandler {
		private String id;

		@Override
		public void characters(char[] ch, int start, int end) {
			id = new String(ch).trim();
		}
	}

	public static String getCRID(String message)
			throws ParserConfigurationException, SAXException, IOException {
		SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
		InputSource is = new InputSource(new StringReader(message));
		MessageHandler handler = new MessageHandler();
		parser.parse(is, handler);
		return handler.id;
	}

}
